//
//  CRSetCell.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRSetCell.h"
#import "CRSetArrowItem.h"
#import "CRSetItem.h"
#import "CRSetSwithItem.h"
@interface CRSetCell ()

/**
 *  箭头
 *
 *  @return
 */
@property (nonatomic, strong) UIImageView *arrowView;

/**
 *  开关
 *
 *  @return
 */
@property (nonatomic, strong) UISwitch *switchView;
/**
 *  标签
 */
@property (nonatomic, strong) UILabel *labelView;


@end

@implementation CRSetCell

- (UIImageView *)arrowView
{
    if (!_arrowView) {
        
        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow"]];
    }
    return _arrowView;
}

- (UISwitch *)switchView
{
    if (!_switchView) {
        
        _switchView = [[UISwitch alloc] init];
    }
    return _switchView;
}

- (UILabel *)labelView
{
    if (!_labelView) {
        _labelView = [[UILabel alloc] init];
        _labelView.bounds = CGRectMake(0, 0, 100, 30);
        _labelView.backgroundColor = [UIColor redColor];
    }
    return _labelView;
}


+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"cell";
    CRSetCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[CRSetCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
    
}



- (void)setItem:(CRSetItem *)item
{
        _item = item;
    
        // 设置数据
        [self setupData];
        // 设置右边的内容
        [self setupRightContent];
}

- (void)setupData
{
    self.imageView.image = [UIImage imageNamed:self.item.icon];
    [self.textLabel setFont:[UIFont boldSystemFontOfSize:15]];
    [self.textLabel setTextColor:[UIColor blackColor]];
    self.textLabel.text = self.item.title;
}


- (void)setupRightContent
{
    if ([self.item isKindOfClass:[CRSetArrowItem class]]) {  // 箭头
        self.accessoryView = self.arrowView;
    }
    
    else if ([self.item isKindOfClass:[CRSetSwithItem class]]){ // 开关
        self.accessoryView = self.switchView;
        // 设置选中的样式
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
//    else if ([self.item isKindOfClass:[SettingLabelItem class]]){ // 标签
//        
//        self.accessoryView = self.labelView;
//        
//    }

    else {
        self.accessoryView = nil;
    }
    
}
@end












